package com.xinyun.client;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelFuture;

/**
 * Created by bubusy on 16/5/22.
 */
public class HeartbeatThread extends Thread {

    private ChannelFuture channelFuture;


    public HeartbeatThread(ChannelFuture channelFuture) {
        this.channelFuture = channelFuture;
    }

    @Override
    public void run() {

        try {
            while (true) {
                Thread.sleep(10000);
                System.out.println("222");
                ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(10);
                buffer.writeShort(2);
                buffer.writeByte(3);
                buffer.writeByte(0);
                buffer.writeByte(0);
                buffer.writeByte(0);
                buffer.writeShort(2345);
                channelFuture.channel().writeAndFlush(buffer);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
